<template>
  <!-- 预览文章弹框 -->
  <el-dialog
    title="预览文章"
    :visible="preVisible"
    width="60%"
    @close="dialogClose"
  >
    <div>
      <h2>{{ preform.title }}</h2>
      <div class="article-baseInfo">
        <span>{{ formatDate(preform.createTime) }}</span>
        <span>{{ username }}</span>
        <i class="el-icon-view"></i>
        <span>{{ preform.visits }}</span>
      </div>
      <div v-html="preform.articleBody" class="article-preview"></div>
    </div>
    <span slot="footer" class="dialog-footer"> </span>
  </el-dialog>
</template>

<script>
import dayjs from "dayjs";

export default {
  props: {
    preVisible: {
      type: Boolean,
      require: true,
    },
    preform: {
      type: Object,
      require: true,
    },
    username: {
      type: String,
      require: true,
    },
  },
  methods: {
    dialogClose() {
      this.$emit("dialog-close");
    },
    // 时间格式转换
    formatDate(date) {
      return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
    },
  },
};
</script>

<style scoped lang='scss'>
.article-baseInfo {
  display: flex;
  margin-bottom: 10px;
  span {
    margin-left: 10px;
  }
  i {
    margin-left: 10px;
  }
}
.article-preview {
  color: #666;
  border-top: 1px dashed #ccc;
  padding-bottom: 30px;
  margin: 0 0 20px 0;
  background: #f5f5f5;
}
</style>
